<?php
error_reporting(E_ALL &~ E_NOTICE);
define('MODULES', 'api,admin');
define('ROOT', __DIR__ . '/');

require('config.php');
require('function.php');
require('library/Database.php');

spl_autoload_register('autoload', TRUE, TRUE);

$moduleName = $_GET['m'];
$controllerName = $_GET['c'];
$actionName = $_GET['a'];

if (!in_array($moduleName, explode(',', MODULES), TRUE)) {
	error404();
	exit;
}
$controllerPath = ROOT . 'modules/' . $moduleName . '/controllers/' . $controllerName . '.php';
if (!is_file($controllerPath)) {
	error404();
	exit;
}
require($controllerPath);
$controllerClass = ucfirst($controllerName) . 'Controller';
$controller = new $controllerClass;
$action = $actionName . 'Action';
if (!method_exists($controllerClass, $action)) {
	error404();
	exit;
}
call_user_func([$controller, $action]);